package engine.ui.chat
{
	import engine.flag.GameDefine;
	import engine.logic.AlertLogic;
	import engine.net.mgr.SystemSender;
	import engine.newUi.GmccLogic;
	
	import flash.events.MouseEvent;
	
	import newx.NxSprite;
	
	public class ChatChannelGroup extends NxSprite
	{
		private var _btnArr	:Array	=	[];
		private var _offset	:int	=	0;
		private var _btnSkin	:String	=	"";
		private var mc			:ChatButton;
		//世界 城堡 家族 组队 本地 系统
		public function ChatChannelGroup(channelData:Array,skin:String="",offset:int=0)
		{
			_btnSkin	=	skin;
			_offset		=	offset;
			
			initGUI(channelData);
		}
		
		private function initGUI(channelData:Array):void
		{
			var posX:int	=	0;
			for(var i:int=0;i<channelData.length;i++)
			{
				var tmpBtn:ChatButton	=	new ChatButton(channelData[i].label,_btnSkin,channelData[i].clickable,channelData[i].type);
				tmpBtn.x	=	posX;
				posX		+=	tmpBtn.width +_offset;
				
				if(channelData[i].enable == true)
				{
					tmpBtn.addEventListener(MouseEvent.CLICK,onItemClick);
					addChild(tmpBtn);	
				}
				_btnArr.push(tmpBtn);
//				if(channelData[i].type == GameDefine.CHATTYPE_WORLD)
//				{
//					tmpBtn.visible = false;
//				}
			}
			graphics.beginFill(0x3c3c3c,.2);
			graphics.drawRect(0,0,width,height);
			graphics.endFill();
		}
		
		public function get btnArr():Array
		{
			return _btnArr;
		}
		
		private function onItemClick(e:MouseEvent):void
		{
			mc 	= e.currentTarget as ChatButton;
			if(mc.label =="求助")
			{
				if(!GmccLogic.getInstance().gmHelpStage)
					SystemSender.getInstance().SendGMCCTOServer("#EXTE#regard");
				else
					if(!GmccLogic.getInstance().gmccUi.created)
						GmccLogic.getInstance().gmccUi.showOrHide();
				return;
			}
			for(var i:int=0;i<_btnArr.length;i++)
			{
				var tmpBtn:ChatButton	=	_btnArr[i];
				tmpBtn.selected			=	false;
			}
			mc.selected	=	true;
			
			ChatLogic.getInstance().dispatchEvent(new ChatEvent(ChatEvent.CHAT_ITEMS_CLICK));
			
		}
		
		public function get clickedBtn():ChatButton
		{
			return mc;
		}
		
		public function get channelTypeArr():Array
		{
			var tmpArr:Array	=	[];
			for(var i:int=0;i<_btnArr.length;i++)
			{
				var tmpBtn:ChatButton	=	_btnArr[i];
				if(tmpBtn.selected)
				{
//					switch(tmpBtn.type)
//					{
////						case GameDefine.CHATTYPE_NATION:
////							tmpArr.push(GameDefine.CHATTYPE_CASTLE_MASTER);
////							break;
//						case GameDefine.CHATTYPE_ALLFRIEND:
//							tmpArr.push(GameDefine.CHATTYPE_ALLFRIEND_ECHO);
//							break;
//						case GameDefine.CHATTYPE_SCENE:
//							tmpArr.push(GameDefine.CHATTYPE_SCENE);
//							break;
//					}			
					if(tmpBtn.type	==	GameDefine.CHATTYPE_All)
					{
						tmpArr.push(GameDefine.CHATTYPE_WORLD_BY_MONEY);
						tmpArr.push(GameDefine.CHATTYPE_GUILD);
					}
					else
					{
						tmpArr.push(tmpBtn.type);
					}
				}
			}
//			tmpArr.push(GameDefine.CHATTYPE_BATTLECAMP);
			tmpArr.push(GameDefine.CHATTYPE_WHISPER);
//			tmpArr.push(GameDefine.CHATTYPE_WORLD);
			tmpArr.push(GameDefine.CHATTYPE_WHISPER_ECHO);
//			tmpArr.push(GameDefine.CHATTYPE_SCENE);
//			tmpArr.push(AlertLogic.TIPSTYPE_LEFTBOTTOM_ACTIVITY_BROADCAST)
			tmpArr.push(AlertLogic.NumberTIPSTYPE_ACTIVITY_BROADCAST)
			tmpArr.push(	AlertLogic.NumberTIPSTYPE_CHAT_BROADCAST)
			tmpArr.push(AlertLogic.TIPSTYPE_LEFTBOTTOM_TIPSINFO )	// 提示信息
			tmpArr.push(	AlertLogic.TIPSTYPE_LEFTBOTTOM_SYSTEM_BROADCAST	)	 // 系统广播
			tmpArr.push(AlertLogic.TIPSTYPE_LEFTBOTTOM_ACTIVITY_BROADCAST)
			return tmpArr;
		}

	}
}